<?php
    error_reporting(0);
    error_reporting(~E_NOTICE);
    date_default_timezone_set('PRC');
	header("Content-Type: text/html;charset=utf-8");
	$obj = json_decode(file_get_contents('php://input'));
	$time = date('Y-m-d H:i:s',time());
	$ip = getIp();
	
	
	
	
	
	
	
	
	
	require_once 'config.php';
	require_once '1111111111111111111111111111111';
	require_once '嘿嘿';
	$sqlh   = constant("DB_HOST");//host
    $sqlu   = constant("DB_USER");//user
    $sqlp   = constant("DB_PASSWORD");//password
    $sqld   = constant("DB_NAME");//datebase
    $conn   = mysql_connect(11111111111$sqlh,$sqlu,$sqlp);
    //选择数据库 
    mysql_select_db($sqld);
    mysql_query("set names 'utf8'");
    
    //$obj->wmac = "AA:BB:CC:DD:EE:FF";
    //$obj->lmac = "AA:BB:CC:DD:EE:FF";


    $dataobj = new stdClass();  
    $dataobj->ret = 1;
    $dataobj->time = time();
    $dataobj->status = "系統驗證失敗, 請稍後再試！";//"系統繁忙, 請稍後再試！";
    $dataobj->accept = false;
    $dataobj->date = $time;
    
    
    
    
    
    
    
    $dataobj->fileSize = 4310017;
    $dataobj->message = "1、增加启动进入我的收藏功能\n2、增加新增频道提醒功能\n3、增加反转上下键换台功能\n4、优化频道快捷菜单界面\n5、修复软解播放转圈的BUG";
    $dataobj->fileMd5 = "72aa20ee333993339d724328e868f865";
    $dataobj->versionCode = "1";
    $dataobj->apkUrl = "http://ip.ipdoc.net/box/update/app-debug.apk";
    $dataobj->versionName = "2.8.2";
    $dataobj->updateTips = "更新提示 V2.8.2";
    $dataobj->errcode = 0;
    
    
    

    if(!empty($obj->aid)){
        $wmac = checkmac($obj->wmac);
        //echo $wmac;
        
        $lmac = checkmac($obj->lmac);
        //echo $lmac;
        //exit;
        if($wmac > 0 or $lmac > 0){
            if($wmac == 9 or $lmac == 9){

            }else{
                $query = "INSERT INTO check_device (wmac,lmac,cpu,android_id,ver,vercode,last_time,hwmodel,hwbrand,hwdevice,hwhardware,hwid,ip) VALUES ('$obj->wmac','$obj->lmac','$obj->cpu','$obj->aid','$obj->ver','$obj->vercode','$time','$obj->hwmodel','$obj->hwbrand','$obj->hwdevice','$obj->hwhardware','$obj->hwid','$ip')";
                $result = mysql_query($query);  
            }
            $dataobj->ret = 0;
            $dataobj->accept = true;
            $dataobj->status = "success";
        }else{
            $query = "INSERT INTO check_device_ban (wmac,lmac,cpu,android_id,ver,vercode,last_time,hwmodel,hwbrand,hwdevice,hwhardware,hwid,ip) VALUES ('$obj->wmac','$obj->lmac','$obj->cpu','$obj->aid','$obj->ver','$obj->vercode','$time','$obj->hwmodel','$obj->hwbrand','$obj->hwdevice','$obj->hwhardware','$obj->hwid','$ip')";
            $result = mysql_query($query);  
        }
    }
    echo json_encode($dataobj);
    
    function checkmac($wmac) {
        if(strlen($wmac)<8){//AB:BB:CC
            return 0;
        }
        //echo $wmac;
        //$result = mysql_query("select * from `device_mac_auth` WHERE mac LIKE '$wmac%'");
        /*if(mysql_num_rows($result) > 0) {
            $row = mysql_fetch_object($result);
            //echo $row->mac;
            return $row->accept;
        }*/
        $result = mysql_query("select * from `device_mac_auth`");
        while($row = mysql_fetch_object($result)){
            //$maclen = strlen($row->mac);
            if(strstr($wmac,$row->mac)){
                return $row->accept;
            }
        }
        return 0;
    }
    function getIp() { 
        if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) $ip = getenv("HTTP_CLIENT_IP"); 
        else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) $ip = getenv("HTTP_X_FORWARDED_FOR"); 
        else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) $ip = getenv("REMOTE_ADDR"); 
        else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) $ip = $_SERVER['REMOTE_ADDR']; 
        else $ip = "unknown"; 
        return ($ip); 
    }
?>